var koa = require('koa');
var router = require('koa-router')();
var views = require('koa-views');
var app = new koa();

//配置ejs模版引擎中间件
app.use(views('views', {
    extension:'ejs'   //ejs模版引擎
}));

//写一个中间件配置公共信息
app.use(async (ctx, next)=>{
    ctx.state.userinfo = '张三';
    await next();       //继续向下匹配路由
})

router.get('/', async(ctx)=>{
    let title = '你好ejs';
    await ctx.render('index', {title:title});
})

router.get('/news', async(ctx)=>{
    let list = ['1111', '2222', '3333'];
    let content = '<h2>这是一个h2</h2>';
    let num = 12;
    await ctx.render('news', {
        list:list,
        content:content,
        num:num
    })
})

app.use(router.routes());
app.use(router.allowedMethods);
app.listen(3000);